package schoolbolg_gh326.Adapter;

import java.util.List;

import schoolbolg_gh326.Bean.BlogBean;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.schoolbolg_gh326.R;

public class BlogAdapter extends BaseAdapter {
	Context context;
	List<BlogBean> list;
	public BlogAdapter(Context context, List<BlogBean>list){
		this.context=context;
		setList(list);
	}
	
	public void setList(List<BlogBean> list){
		this.list=list;
	}
	public void clearList(){
		list.clear();
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		if (convertView==null) {
			holder=new ViewHolder();
			convertView=LayoutInflater.from(context).inflate(R.layout.item_blog, null);
			holder.name=(TextView)convertView.findViewById(R.id.textView_item_blog_name);
			holder.tel=(TextView)convertView.findViewById(R.id.textView_item_blog_tel);
			convertView.setTag(holder);
		}else{
			holder=(ViewHolder)convertView.getTag();
		}
		
		BlogBean blogBean=list.get(position);
		holder.name.setText(blogBean.getName());
		holder.tel.setText(blogBean.getTel());
		
	return convertView;
	}
	class ViewHolder{
		private TextView name;
		private TextView tel;
	}
}
